using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{
    [Table(Name = "dbo.EnPower")]
    public partial class EnPower : Entity
    {

        private decimal _powerNum;

        private decimal _enTypeNum;

        private string _powerCont;

        private decimal _txNum;

        private EntitySet<EnST> _EnST;

        private EntityRef<TX> _TX;

        public EnPower()
        {
            this._EnST = new EntitySet<EnST>(new Action<EnST>(this.attach_EnST), new Action<EnST>(this.detach_EnST));
            this._TX = default(EntityRef<TX>);
        }

        [Column(Storage = "_powerNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal PowerNum
        {
            get
            {
                return this._powerNum;
            }
            set
            {
                if ((this._powerNum != value))
                {
                    this.SendPropertyChanging("PowerNum");
                    this._powerNum = value;
                    this.SendPropertyChanged("PowerNum",value);
                }
            }
        }

        [Column(Storage = "_enTypeNum", DbType = "Decimal(18,0)")]
        public decimal EnTypeNum
        {
            get
            {
                return this._enTypeNum;
            }
            set
            {
                if ((this._enTypeNum != value))
                {
                    this.SendPropertyChanging("EnTypeNum");
                    this._enTypeNum = value;
                    this.SendPropertyChanged("EnTypeNum",value);
                }
            }
        }

        [Column(Storage = "_powerCont", DbType = "VarChar(8000) NOT NULL", CanBeNull = false)]
        public string PowerCont
        {
            get
            {
                return this._powerCont;
            }
            set
            {
                if ((this._powerCont != value))
                {
                    this.SendPropertyChanging("PowerCont");
                    this._powerCont = value;
                    this.SendPropertyChanged("PowerCont",value);
                }
            }
        }

        [Column(Storage = "_txNum", DbType = "Decimal(18,0)")]
        public decimal TXNum
        {
            get
            {
                return this._txNum;
            }
            set
            {
                if ((this._txNum != value))
                {
                    if (this._TX.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("TXNum");
                    this._txNum = value;
                    this.SendPropertyChanged("TXNum",value);
                }
            }
        }

        [Association(Name = "EnPower_EnST", Storage = "_EnST", ThisKey = "PowerNum", OtherKey = "PowerNum")]
        public EntitySet<EnST> EnST
        {
            get
            {
                return this._EnST;
            }
            set
            {
                this._EnST.Assign(value);
            }
        }

        [Association(Name = "TX_EnPower", Storage = "_TX", ThisKey = "TXNum", OtherKey = "TXNum", IsForeignKey = true)]
        public TX TX
        {
            get
            {
                return this._TX.Entity;
            }
            set
            {
                TX previousValue = this._TX.Entity;
                if (((previousValue != value)
                            || (this._TX.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("TX");
                    if ((previousValue != null))
                    {
                        this._TX.Entity = null;
                        previousValue.EnPower.Remove(this);
                    }
                    this._TX.Entity = value;
                    if ((value != null))
                    {
                        value.EnPower.Add(this);
                        this._txNum = value.TXNum;
                    }
                    else
                    {
                        this._txNum = default(decimal);
                    }
                    this.SendPropertyChanged("TX",value);
                }
            }
        }

        private void attach_EnST(EnST entity)
        {
            entity.EnPower = this;
        }

        private void detach_EnST(EnST entity)
        {
            entity.EnPower = null;
        }
    }
}
